<?php

namespace Tests;

abstract class TestCase extends \Laravel\Lumen\Testing\TestCase
{
    protected $baseUrl = 'http://study-api';

    protected $headers = [
        'X-Consumer-Username' => 'student',
        'X-Authenticated-Userid' => 2,
        'X-Authenticated-Scope' => 'student',
    ];

    /**
     * Creates the application.
     *
     * @return \Laravel\Lumen\Application
     */
    public function createApplication()
    {
        return require __DIR__.'/../bootstrap/app.php';
    }

    /**
     * @return array
     */
    public function uidProvider(string $testfunc, $count=5)
    {
        return array_map(
            function($item) {
                return [$item];
            },
            range(1,$count)
        );
    }

    public function setUserId($userId)
    {
        $this->headers['X-Authenticated-Userid'] = $userId;
    }

    public function get($url, array $data=[], array $headers=[])
    {
        $headers = $headers ? $headers : $this->headers;
        if ($data) {
            $url .= '?' . http_build_query($data);
        }
        return parent::get($url, $headers);
    }

    public function post($url, array $data=[], array $headers=[])
    {
        $headers = $headers ? $headers : $this->headers;
        return parent::post($url, $data, $headers);
    }

    public function put($url, array $data=[], array $headers=[])
    {
        $headers = $headers ? $headers : $this->headers;
        return parent::put($url, $data, $headers);
    }

    public function delete($url, array $data=[], array $headers=[])
    {
        $headers = $headers ? $headers : $this->headers;
        return parent::delete($url, $data, $headers);
    }
}
